<?php
include("config.php");
	function Select()
		{ 
			$sql="Select * from loai where 1=1";
			$result=mysql_query ($sql);
			if (!$result or mysql_num_rows ($result)==0)
			{		
				
			}
			else
			{
			$tmp='<select name="cate" id="cate">
			<option value=>chon mot loai xe</option>';
			while ($line=mysql_fetch_assoc ($result))
			{
			
			$tmp.=" <option value=\"{$line["category_id"]}\">{$line["product_cate"]}</option> \n";
			}
			$tmp.="</select>";
			}
			return $tmp;
		}

?>
<html>
<head>
<script language="javascript">
function onsubmit()
		{
			var f=document.frm;
			var id=f.product_id.value;
			var name=f.product_name.value;
			var des=f.product_desc.value;
			var price=f.price.value;
			var cate=f.cate.value;
			var s=0;
			if(id=="")
			{
				alert("id ko dc de rong");
				s=1;
				return false;
			}
			else
			{
				if(isNaN(id))
					{
						alert("id phai la so");
						return false;
					}
				else
					if(name=="")
				{
					alert("name ko dc de rong");
					s=1;
					return false;
				}	
				if(des=="")
				{
					alert("des ko dc de rong");
					s=1;
					return false;
				}					
				if(price=="")
				{
					alert("price ko dc de rong");
					s=1;
					return false;
				}
				else
				{	if(isNaN(price))
					{
						alert("price phai la so");
						return false;
					}
					else
					if(cate=="")
					{
						alert("chon mot loai san pham");
						s=1;
						return false;
					}	
								
					if(s!=1){
					f.act.value=1;
					f.submit();
					}
				}
			}
			
		}
</script>
<style>
</style>
</head>
<body>
<center>
<form name="frm" method="POST" action="xl_form.php">
	<table style="background:#336699" width="400">
		<tr>
			<td>
				<tr>
					<td>product_ID:</td>
					<td><input type="text" value="" name="product_id">
					<input name="act" value="" type="hidden" ></td>
				</tr>
					<td>product_name:</td>
					<td><input type="text" value="" name="product_name" ></td>
				<tr>
					<td>product_Description:</td>
					<td><input type="text" value="" name="product_desc" ></td>
				</tr>
				<tr>
					<td>Price:</td>
					<td><input type="text" value="" name="price" ></td>
				</tr>
				<tr>
					<td>category:</td>
					<td><?php echo (Select());?></td>
				</tr>
				<tr>
					<td></td>
					<td><input type="submit" name="save" value="save" ></td>
				</tr>
			</td>
		</tr>
	</table>
</form>
</center>
</body>
</html>
<?php
include("config.php");
?>
